home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000085_icon-group-sender _Fri May 14 09:46:40 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 14 May 1993 08:58:37 MST
  2. Date: Fri, 14 May 93 09:46:40 -0400
  3. Message-Id: <9305141346.AA10725@sanborn.bbn.com>
  4. To: icon-group@cs.arizona.edu
  5. Subject: string stripping
  6. From: Sean Boisen <sboisen@BBN.COM>
  7. Sender: sboisen@bbn.com
  8. Reply-To: sboisen@bbn.com
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. This is so basic it's probably covered in the second week of Icon 101,
  13. but since i never took the class ...
  14.  
  15. If i have a string and i want to strip out certain characters
  16. (internal ones, so trim won't do it), i can do it like this
  17.  
  18. # assume you want to remove hyphens and periods
  19. full := "abc-def.ghi"
  20. bare := ""
  21. badchars := '-.'
  22.  
  23. every c := !full do
  24.    # test whether the intersection of c and badchars is empty
  25.    if *(c ** badchars) = 0 then bare ||:= c
  26.  
  27. But this seems awfully clunky, and i was disappointed that i couldn't
  28. come up with a tighter way to do it: am i missing some more idiomatic
  29. way to express this? Note there's two parts that i perceive as clunky:
  30. the testing of whether c is in badchars (i suppose you could make
  31. badchars a string and use find instead), and the control structure
  32. with explicit generation and assignment to a new string.
  33.  
  34. Any Icon stylists want to offer some pointers on improvements? 
  35.  
  36. Sean
  37.  
  38.